package SessionLogin;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; 

@WebServlet("/SessionLoginServlet")
public class SessionLoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;


    private static final String USERNAME = "admin";
    private static final String PASSWORD = "123456";

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        String username = request.getParameter("username");
        String password = request.getParameter("password");


        if (USERNAME.equals(username) && PASSWORD.equals(password)) {

            HttpSession session = request.getSession();

            session.setAttribute("username", username);

            response.sendRedirect("sessionWelcome.jsp");
        } else {

            response.sendRedirect("sessionLogin.jsp");
        }
    }
}